/**********************************************************************************
* CLASS
*		ExternalEmbeded
*
* DESCRIPTION
* 		Code from external embeded
*
* REVISION HISTORY
*		Revision 1.0 2008/12/21 Atthaboon S.
*		First Release
*
**********************************************************************************/
var ExternalEmbeded = Class.create({

	/****************************************************
	* FUNCTION
	*		initialize
	*
	* DESCRIPTION
	* 		initialize the Genesis object.
	*
	* ARGUMENTS
	*		position_x		:	position of x at north left Genesis corner.
	*		position_y 	   	:	position of y at north left Genesis corner.
	*		code			:	string of embeded code
	*
	****************************************************/
  	initialize: function(position_x,position_y,code)
  	{
		this.domObj = new Element('div', { 'style':'position:absolute; left:'+position_x+'px;top:'+position_y+'px;overflow:hidden; width: 300px; height:300px;'});
		this.domObj.innerHTML = code;
		
		this.property = null;
	},
	
	/****************************************************
	* FUNCTION 
	*		getDomType
	*
	* DESCRIPTION
	* 		Use by Genesis for get Genesis dom Component Type.
	*
	* ARGUMENTS
	*
	****************************************************/
	getDomType : function()
	{
		return "ExternalEmbeded";
	},	
	
	/****************************************************
	* FUNCTION 
	*		getDomObj
	*
	* DESCRIPTION
	* 		Use by Genesis for get image dom Component.
	*
	* ARGUMENTS
	*
	****************************************************/
	getDomObj : function()
	{
		return this.domObj;
	},
	
	/****************************************************
	* FUNCTION 
	*		getProperty
	*
	* DESCRIPTION
	* 		Get ExternalEmbeded Property
	*
	* ARGUMENTS
	*
	****************************************************/	
	getProperty : function()
	{	
		// Is not generate property yet do generate it's
		if(this.property == null)
		{
			this.generatePropertyBar();
		}
		else if(this.property.getDomObj().innerHTML == '')
		{
			this.generatePropertyBar();
		}
		return this.property.getDomObj();
	},
	
	/****************************************************
	* FUNCTION 
	*		generatePropertyBar
	*
	* DESCRIPTION
	* 		Generate Dom Property Bar
	*
	* ARGUMENTS
	*
	****************************************************/
	generatePropertyBar : function()
	{
		var  ExternalEmbededDomObj = $(this.domObj);
	
		this.property = new PropertyBar("Content",600);
		this.width_box       	  = this.property.addTextBox('Width','px','5',0);
		this.width_box.value      = parseInt($(this.domObj).style.width);
		this.width_box.onchange   = function() {
			ExternalEmbededDomObj.style.width = this.value+'px';
			setResizeAreaPosition(_dragElement);
		}
		
		this.height_box      	  = this.property.addTextBox('Height','px','5',0);
		this.height_box.value     = parseInt($(this.domObj).style.height);
		this.height_box.onchange   = function() {
			ExternalEmbededDomObj.style.height = this.value+'px';
			setResizeAreaPosition(_dragElement);
		}
		
		this.position_x_box  	  = this.property.addTextBox('Positon X','px','5',1);
		this.position_x_box.value = parseInt($(this.domObj).style.left);
		this.position_x_box.onchange   = function() {
			ExternalEmbededDomObj.style.left = this.value+'px';
			setResizeAreaPosition(_dragElement);
		}
		
		this.position_y_box  	  = this.property.addTextBox('Positon Y','px','5',1);
		this.position_y_box.value = parseInt($(this.domObj).style.top);
		this.position_y_box.onchange   = function() {
			ExternalEmbededDomObj.style.top = this.value+'px';
			setResizeAreaPosition(_dragElement);
		}
		
		// Code area
		var edit_code_area_Obj	  = this.property.addTextArea('Code embeded','',0);
		edit_code_area_Obj.value = $(this.domObj).innerHTML;
		
		// Submit Code
		this.submid_code_button   = this.property.addButton('Submit code',1);
		this.submid_code_button.onmousedown = function() {
			ExternalEmbededDomObj.innerHTML = edit_code_area_Obj.value;
		}
	},
	
	/****************************************************
	* FUNCTION 
	*		syncProperty
	*
	* DESCRIPTION
	* 		Sync Image Property
	*
	* ARGUMENTS
	*
	****************************************************/	
	syncProperty : function()
	{
		this.width_box.value      = parseInt($(this.domObj).style.width);
		this.height_box.value     = parseInt($(this.domObj).style.height);
		this.position_x_box.value = parseInt($(this.domObj).style.left);
		this.position_y_box.value = parseInt($(this.domObj).style.top);
	},
	
	/****************************************************
	* FUNCTION 
	*		setSize
	*
	* DESCRIPTION
	* 		Set Content size.
	*
	* ARGUMENTS
	*		width		   		:	width in px.
	*		height 	   	   	:	height in px.
	*
	****************************************************/
	setSize : function(width,height)
	{	
		$(this.domObj).setStyle({
		  	width: width+'px',
		  	height: height+'px'
		});
	},
	
	/****************************************************
	* FUNCTION 
	*		setPosition
	*
	* DESCRIPTION
	* 		Set Flash position.
	*
	* ARGUMENTS
	*		position_x		   	:	position x in px.
	*		position_y 	   	   	:	position y in px.
	*
	****************************************************/
	setPosition : function(position_x,position_y)
	{	
		$(this.domObj).setStyle({
		  	left: position_x+'px',
		  	top: position_y+'px'
		});
	},
	
	/****************************************************
	* FUNCTION 
	*		setCode
	*
	* DESCRIPTION
	* 		Set Embeded code.
	*
	* ARGUMENTS
	*		code			: embeded code string
	*
	****************************************************/
	setCode : function(code)
	{	
		this.domObj.innerHTML = code;
	}
});